package com.xiao.xin.core.service.Impl;

import com.xiao.xin.core.domain.ComfyuiModel;
import com.xiao.xin.core.service.FreemarkerService;
import freemarker.template.Configuration;
import freemarker.template.Template;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.io.StringWriter;
import java.util.HashMap;
import java.util.Map;


@Service
@RequiredArgsConstructor
public class FreemarkerServiceImpl implements FreemarkerService {

    private final Configuration configuration;

    @Override
    public String renderText2Image(ComfyuiModel model) throws Exception {
        Template template = configuration.getTemplate("t2i.ftlh");
        Map<String,Object> map = new HashMap<>();
        StringWriter stringWriter = new StringWriter();
        map.put("config",model);
        template.process(map,stringWriter);
        return stringWriter.toString();
    }
}
